<?php global $ubi; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<title>TÙM LUM site</title>
        
		<link href="include/css/style.css" media="screen" rel="stylesheet" type="text/css" />
		<link href="include/css/styles.css" type="text/css" media="all" rel="stylesheet" id="contact-form-7-css" />
        <link href="include/css/site.css" media="screen" type="text/css" rel="stylesheet" />
		<link href="include/css/jquery.wysiwyg.css" type="text/css" rel="stylesheet" />
		<link href="include/css/jquery-ui.css" type="text/css" rel="stylesheet" />
		
		<script language="javascript" type="text/javascript" src="include/script/jquery-1.4.4.min.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript" src="include/script/script.js"></script>
		<script language="javascript" type="text/javascript" src="include/script/jquery-ui-1.8.14.custom.min.js"></script>  
		<script language="javascript" type="text/javascript" src="include/script/jquery.wysiwyg.js"></script>
		<script language="javascript" type="text/javascript" src="include/script/script.js"></script>

		<script language="javascript" type="text/javascript">
			$(document).ready(function(){
				$('#randomItemProvider').load('index.php?load&view=randomItemProvider');
				$('#blockSignIn').load('index.php?load&view=blockSignIn');
				$('#blockSearch').load('index.php?load&view=blockSearch');
				$('#blockMembers').load('index.php?load&view=blockMembers');
				$('#blockNewestPosts').load('index.php?load&view=blockNewestPosts');
				$('#mainMenu').load('index.php?load&view=menu');
				$('#footer').load('index.php?load&view=footer');

				$('#item_input').wysiwyg();
				
				$('#lnkAddItemCategory').click(function() {
					var val = $('#selCatItem2 option:selected').val();
	
					var arrCat = [];
					$('input[class=hiddenCatItemID]').each(function(index) {
						arrCat.push($(this).val());		    
					});
					var ok = true;
					for (var i = 0; i < arrCat.length; i++) {
						if (arrCat[i] == val) {
							ok = false;							
							break;
						}
					}

					if (ok) {
						$('#messCat').hide();
						var newRow = '<tr><td>' + $('#selCatItem1 option:selected').html() + '</td>' 
										+ '<td>' + $('#selCatItem2 option:selected').html() + '</td>' 
										+ '<td>' + '<input type="button" value="Xóa" onclick="$.removeCat(this)"></td>'
										+ '<td><input type="hidden" class="hiddenCatItemID" value="' + val + '" /></td>' 
									+'</tr>';
						$('#tblCatItem tr:last').after(newRow);
						var url = 'index.php?input&action=getCategoryItemQuestion';
						$.post(url, {'cat' : val}, function(data){
							var str = '<div id="cat' + val + '">' + $.getStringFromXMLQuestions(data) + '</div>';							
							$('#blockDanhGia').append(str);							
						});
					} else {
						$('#messCat').html('Phân loại này đã được chọn. Bạn hãy chọn một phân loại khác !!!');
						$('#messCat').show();
					}
				});
	
				$('#frmUpdateItem').submit(function() {
					var str = '';
					if ($('#frmUpdateItem [name=txtItemName]').val() == '') {			
						str += 'Bạn chưa nhập tên item\n';
					}
					if ($('#frmUpdateItem [name=txtNumber]').val() == '') {
						str += 'Bạn chưa nhập số nhà\n';
					}
					if ($('#frmUpdateItem [name=txtStreet]').val() == '') {
						str += 'Bạn chưa nhập số nhà\n';
					}				
	
					if (str != '') {
						alert(str);
						return false;
					}	
	
					var str = '';
					$('input[class=hiddenCatItemID]').each(function(index) {
						str += ' ' + $(this).val();		    
					});		
					$('input[name=categoryItemList][type=hidden]').val(str);

					var answerList = '';
					$('#frmUpdateItem input[type=radio]').each(function(index) {
						if ($(this).attr('checked')) {
							answerList += $(this).val() + ' ';
						}		    
					});
					$('input[name=answerList]').val(answerList);
					
					return true;
				});
	
				$('#frmUpdateItem [name=selUnit]').val('<?php $itemModel->getUnit()?>');

				$('#selCatItem1').change(function() {
					pid = $('#selCatItem1 option:selected').val();
					url = 'index.php?input&action=getCategoryItem';

					$.doPostGetCategoryList(pid, '#selCatItem2', url);				
				});

				var arrCat = [];
				var strArrCat = '<?php echo $itemModel->getCategoryList()?>';
				arrCat = strArrCat.split(' ');
				for (var i = 0; i < arrCat.length; i++) {
					$.getTextFromCategory(arrCat[i]);
				}
			});

			var arrAnswer = [];
			var strAnswerList = '<?php echo $itemModel->getAnswerList()?>';
			arrAnswer = strAnswerList.split(' ');
			
			$.extend({
				removeCat:function(tag) {
					$.removeRow(tag);
					var val = $(tag).parent().parent().find('input[type=hidden]').val();
					$('#cat' + val).remove();
				},
				getTextFromCategory:function(val) {
					var url = 'index.php?input&action=getCategoryItemQuestion';
					$.post(url, {'cat' : val}, function(data){
						var str = '<div id="cat' + val + '">' + $.getStringFromXMLQuestions(data) + '</div>';							
						$('#blockDanhGia').append(str);

						for (var i = 0; i < arrAnswer.length; i++) {
							var question_answer = arrAnswer[i].split('-');
							$('input[name=' + question_answer[0] + ']').
								filter("[value="+question_answer[0]+"-"+question_answer[1]+"]").
								attr("checked","checked");
						}					
					});
				}
			});
    	</script>
	</head>

	<body id="cookoffboard" class="home blog">
		<div id="corners">			
			<div class="header" id="main-head">
				<div id="hdr-info">
                	<div style="float:left">
                        <img id="logo" src="include/imgs/logo4.png" alt="The Cook-Off Board" width="235px" />
                        <p id="desc">Tùm Lum, Tả Pí Lù, chia sẻ tất cả ở đây</p>
                    </div>
                    <div class="nav">
                        <div id="mainMenu"></div>
                        <div style="clear:both"></div>
                    </div>
				</div>             
			</div> <!--end header-->
            
			<div class="polaroids">
            	<div class="marginBoxPicCollection" id="randomItemProvider"></div>
			</div> <!--end polaris-->
            
            <div id="container">
				<hr />
                <div class="left">
                    <div class="section" id="content">
                    	<h1>Cập nhật thông tin địa điểm</h1>
                        <form name="frmUpdateItem" id="frmUpdateItem" action="index.php?item&action=update" method="post">
							<fieldset class="form">
						    	<ul class="frm">
						        	<li class="input">
				                    	<label>Tên Item</label>
				                        <input type="text" name="txtItemName" value="<?php echo $itemModel->getItem()?>" />	                        
			                    	</li>
			                    	<li class="input">
				                    	<label>Đơn vị</label>
				                        <select name="selUnit">
						                   	<option value="Tô">Tô</option>
						                	<option value="Viên">Viên</option>
						                    <option value="Ký">Ký</option>
						                    <option value="Phần">Phần</option>
						                    <option value="Ly">Ly</option>
										</select>	                        
			                    	</li>	   
			                    	<li class="input">
			                    		<label>Phân loại</label>                    		                	
					                	<table id="tblCatItem">
					                    	<tr>
					                        	<td>
					                                <select name="selCatItem1" id="selCatItem1">
					                                	<?php			                                		
					                                		$catItem =  $arrCatItem1[0];
					                                	    for ($i = 0; $i < count($arrCatItem1); $i++) {
					                                			$catItem = $arrCatItem1[$i];                                	
					                                	?>
					                                	<option value="<?php echo $catItem->getCategoryID();?>"><?php echo $catItem->getCategory();?></option>
					                                	<?php 		
					                                		} 
					                                	?>	
					                                </select>
					                            </td>
					                            <td>
					                                <select name="selCatItem2" id="selCatItem2">
					                                    <?php
					                                		$catItem =  $arrCatItem2[0];
					                                	    for ($i = 0; $i < count($arrCatItem2); $i++) {
					                                			$catItem = $arrCatItem2[$i];                                	
					                                	?>
					                                	<option value="<?php echo $catItem->getCategoryID();?>"><?php echo $catItem->getCategory();?></option>
					                                	<?php 		
					                                		} 
					                                	?>                            	
						                            </select>
					                            </td>
					                            <td><input type="button" id="lnkAddItemCategory" value="Thêm" /></td>
					                            <td></td>                            
											</tr>           
											<?php
				                    			for ($i = 0; $i < count($arrCat); $i++) {
				                    				$cat = $arrCat[$i];
				                    				$catParent = $arrCatParent[$i];
				                    		?>
			                    			<tr>
			                    				<td><?php echo $catParent->getCategory()?></td>
			                    				<td><?php echo $cat->getCategory()?></td>
			                    				<td><input type="button" onclick="$.removeCat(this)" value="Xóa" /></td>
			                    				<td><input type="hidden" class="hiddenCatItemID" value="<?php echo $cat->getCategoryID()?>" /></td>
			                    			</tr>
				                    		<?php 
				                    			} 
				                    		?>                   		                                		
										</table>				            
			                    	</li>
			                    	
			                    	<li class="input">            	
						            	<label for="giasan">Giá Từ</label>
						            	<input type="text" name="txtPriceFrom" value="<?php echo $itemModel->getBeginPrice()?>" />	           	
						            </li>
						            
						            <li class="input">
						            	<label for="giatran">Giá Đến</label>
						            	<input type="text" name="txtPriceTo" value="<?php echo $itemModel->getEndPrice()?>" />
						            </li>
						            			                   
									<li class="input">															
						            	<label for="hinhanh">Địa Điểm</label>
						            	<a href="index.php?view&type=provider&id=<?php echo $itemModel->getProviderID()?>"><?php echo $providerModel->getProvider()?></a>
						            </li>
						            
						            <li class="input">
						            	<label for="danhgia">Đánh Giá</label>                                    
						                <div style="display:inline-block;" id="blockDanhGia"></div>                                                      
						            </li>
						            
						            <li class="input">
						            	<label for="mota">Mô Tả</label>
						                <div></div>
									</li>
								</ul>
								
								<div style="clear:both"></div>		            				                
				        		<textarea id="item_input" class="textarea_input" rows="10" cols="70" name="txtItemDes">
					                <?php echo $itemModel->getDescription()?>	
					            </textarea>
							    <br />   			                	
								
								<input type="hidden" name="categoryItemList" />
								<input type="hidden" name="answerList" value="<?php echo $itemModel->getAnswerList()?>" />                	            
								<input type="hidden" name="itemID" value="<?php echo $itemModel->getItemID()?>" />		        		        
					            <input type="submit" value="Cập nhật" />
							</fieldset>						    
						</form>
						<div class="clear"></div>                     
                    </div>  <!--end section -->
            	</div> <!-- end left -->        
                <div class="right">
        			<div class="aside">
                        <ul class="blockRightSide">	
                            <li class="blockRight" id="blockSignIn"></li>
                            <li class="blockRight" id="blockSearch"></li>                                            
                            <li class="blockRight" id="blockMembers"></li>
                            <li class="blockRight" id="blockNewestPosts"></li>                          
                        </ul>
                    </div>        
                </div> <!--end right-->
			</div> <!--end container-->		
            
           <div id="footer" class="footer clearfix"></div>
		</div>
	</body>
</html>